home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 21
/
Cream of the Crop 21 (Terry Blount) (October 1996).iso
/
os2
/
e33el2.zip
/
emacs
/
19.33
/
lisp
/
pascal.el
< prev
next >
Wrap
Lisp/Scheme
|
1996-05-23
|
57KB
|
1,559 lines
;;; pascal.el --- major mode for editing pascal source in Emacs
;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
;; Author: Espen Skoglund (espensk@stud.cs.uit.no)
;; Keywords: languages
;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; USAGE
;; =====
;; Emacs should enter Pascal mode when you find a Pascal source file.
;; When you have entered Pascal mode, you may get more info by pressing
;; C-h m. You may also get online help describing various functions by:
;; C-h f <Name of function you want described>
;; If you want to customize Pascal mode to fit you better, you may add
;; these lines (the values of the variables presented here are the defaults):
;;
;; ;; User customization for Pascal mode
;; (setq pascal-indent-level 3
;; pascal-case-indent 2
;; pascal-auto-newline nil
;; pascal-tab-always-indent t
;; pascal-auto-endcomments t
;; pascal-auto-lineup '(all)
;; pascal-toggle-completions nil
;; pascal-type-keywords '("array" "file" "packed" "char"
;; "integer" "real" "string" "record")
;; pascal-start-keywords '("begin" "end" "function" "procedure"
;; "repeat" "until" "while" "read" "readln"
;; "reset" "rewrite" "write" "writeln")
;; pascal-separator-keywords '("downto" "else" "mod" "div" "then"))
;; KNOWN BUGS / BUGREPORTS
;; =======================
;; As far as I know, there are no bugs in the current version of this
;; package. This may not be true however, since I never use this mode
;; myself and therefore would never notice them anyway. If you do
;; find any bugs, you may submit them to: espensk@stud.cs.uit.no
;; as well as to bug-gnu-emacs@prep.ai.mit.edu.
;;; Code:
(defvar pascal-mode-abbrev-table nil
"Abbrev table in use in Pascal-mode buffers.")
(define-abbrev-table 'pascal-mode-abbrev-table ())
(defvar pascal-mode-map ()
"Keymap used in Pascal mode.")
(if pascal-mode-map
()
(setq pascal-mode-map (make-sparse-keymap))
(define-key pascal-mode-map ";" 'electric-pascal-semi-or-dot)
(define-key pascal-mode-map "." 'electric-pascal-semi-or-dot)
(define-key pascal-mode-map ":" 'electric-pascal-colon)
(define-key pascal-mode-map "=" 'electric-pascal-equal)
(define-key pascal-mode-map "#" 'electric-pascal-hash)
(define-key pascal-mode-map "\r" 'electric-pascal-terminate-line)
(define-key pascal-mode-map "\t" 'electric-pascal-tab)
(define-key pascal-mode-map "\M-\t" 'pascal-complete-word)
(define-key pascal-mode-map "\M-?" 'pascal-show-completions)
(define-key pascal-mode-map "\177" 'backward-delete-char-untabify)
(define-key pascal-mode-map "\M-\C-h" 'pascal-mark-defun)
(define-key pascal-mode-map "\C-c\C-b" 'pascal-insert-block)
(define-key pascal-mode-map "\M-*" 'pascal-star-comment)
(define-key pascal-mode-map "\C-c\C-c" 'pascal-comment-area)
(define-key pascal-mode-map "\C-c\C-u" 'pascal-uncomment-area)
(define-key pascal-mode-map "\M-\C-a" 'pascal-beg-of-defun)
(define-key pascal-mode-map "\M-\C-e" 'pascal-end-of-defun)
(define-key pascal-mode-map "\C-c\C-d" 'pascal-goto-defun)
(define-key pascal-mode-map "\C-c\C-o" 'pascal-outline)
;;; A command to change the whole buffer won't be used terribly
;;; often, so no need for a key binding.
; (define-key pascal-mode-map "\C-cd" 'pascal-downcase-keywords)
; (define-key pascal-mode-map "\C-cu" 'pascal-upcase-keywords)
; (define-key pascal-mode-map "\C-cc" 'pascal-capitalize-keywords)
)
(defvar pascal-imenu-generic-expression
'("^[ \t]*\\(function\\|procedure\\)[ \t\n]+\\([a-zA-Z0-9_.:]+\\)" . (2))
"Imenu expression for Pascal-mode. See `imenu-generic-expression'.")
(defvar pascal-keywords
'("and" "array" "begin" "case" "const" "div" "do" "downto" "else" "end"
"file" "for" "function" "goto" "if" "in" "label" "mod" "nil" "not" "of"
"or" "packed" "procedure" "program" "record" "repeat" "set" "then" "to"
"type" "until" "var" "while" "with"
;; The following are not standard in pascal, but widely used.
"get" "put" "input" "output" "read" "readln" "reset" "rewrite" "write"
"writeln"))
;;;
;;; Regular expressions used to calculate indent, etc.
;;;
(defconst pascal-symbol-re "\\<[a-zA-Z_][a-zA-Z_0-9.]*\\>")
(defconst pascal-beg-block-re "\\<\\(begin\\|case\\|record\\|repeat\\)\\>")
(defconst pascal-end-block-re "\\<\\(end\\|until\\)\\>")
(defconst pascal-declaration-re "\\<\\(const\\|label\\|type\\|var\\)\\>")
(defconst pascal-defun-re "\\<\\(function\\|procedure\\|program\\)\\>")
(defconst pascal-sub-block-re "\\<\\(if\\|else\\|for\\|while\\|with\\)\\>")
(defconst pascal-noindent-re "\\<\\(begin\\|end\\|until\\|else\\)\\>")
(defconst pascal-nosemi-re "\\<\\(begin\\|repeat\\|then\\|do\\|else\\)\\>")
(defconst pascal-autoindent-lines-re
"\\<\\(label\\|var\\|type\\|const\\|until\\|end\\|begin\\|repeat\\|else\\)\\>")
;;; Strings used to mark beginning and end of excluded text
(defconst pascal-exclude-str-start "{-----\\/----- EXCLUDED -----\\/-----")
(defconst pascal-exclude-str-end " -----/\\----- EXCLUDED -----/\\-----}")
(defvar pascal-mode-syntax-table nil
"Syntax table in use in Pascal-mode buffers.")
(if pascal-mode-syntax-table
()
(setq pascal-mode-syntax-table (make-syntax-table))
(modify-syntax-entry ?\\ "." pascal-mode-syntax-table)
(modify-syntax-entry ?( "()1" pascal-mode-syntax-table)
(modify-syntax-entry ?) ")(4" pascal-mode-syntax-table)
(modify-syntax-entry ?* ". 23" pascal-mode-syntax-table)
(modify-syntax-entry ?{ "<" pascal-mode-syntax-table)
(modify-syntax-entry ?} ">" pascal-mode-syntax-table)
(modify-syntax-entry ?+ "." pascal-mode-syntax-table)
(modify-syntax-entry ?- "." pascal-mode-syntax-table)
(modify-syntax-entry ?= "." pascal-mode-syntax-table)
(modify-syntax-entry ?% "." pascal-mode-syntax-table)
(modify-syntax-entry ?< "." pascal-mode-syntax-table)
(modify-syntax-entry ?> "." pascal-mode-syntax-table)
(modify-syntax-entry ?& "." pascal-mode-syntax-table)
(modify-syntax-entry ?| "." pascal-mode-syntax-table)
(modify-syntax-entry ?_ "w" pascal-mode-syntax-table)
(modify-syntax-entry ?\' "\"" pascal-mode-syntax-table))
(defvar pascal-font-lock-keywords
(list
'("^[ \t]*\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
; ("type" "const" "real" "integer" "char" "boolean" "var"
; "record" "array" "file")
(cons (concat "\\<\\(array\\|boolean\\|c\\(har\\|onst\\)\\|file\\|"
"integer\\|re\\(al\\|cord\\)\\|type\\|var\\)\\>")
'font-lock-type-face)
'("\\<\\(label\\|external\\|forward\\)\\>" . font-lock-reference-face)
'("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-reference-face)
; ("of" "to" "for" "if" "then" "else" "case" "while"
; "do" "until" "and" "or" "not" "in" "with" "repeat" "begin" "end")
(concat "\\<\\("
"and\\|begin\\|case\\|do\\|e\\(lse\\|nd\\)\\|for\\|i[fn]\\|"
"not\\|o[fr]\\|repeat\\|t\\(hen\\|o\\)\\|until\\|w\\(hile\\|ith\\)"
"\\)\\>")
'("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
(1 font-lock-keyword-face) (2 font-lock-reference-face nil t)))
"Add